package gptma.bo.model.task;

import gptma.bo.model.BaseEntity;
import gptma.bo.model.employee.Employee;

import java.util.Date;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.BatchSize;

@BatchSize(size = 30)
// batch fetch list of imputations after having been fetched from cache
@Entity
@Table(name = "imputation")
@AttributeOverride(name = "id", column = @Column(name = "imputationId"))
public class Imputation extends BaseEntity implements Comparable<Imputation> {

	private static final long serialVersionUID = 4341332884944890851L;

	@Temporal(value = TemporalType.TIMESTAMP)
	@Column(name = "date")
	private Date date;

	@Digits(integer = 1, fraction = 2)
	@Column(name = "consomme")
	private Float charge;

	@Digits(integer = 2, fraction = 2)
	@Column(name = "RAF")
	private Float etc;

	@NotNull
	@Column(name = "commentaire")
	private String comment;

	@ManyToOne
	@JoinColumn(name = "tacheId")
	private Task task;

	@ManyToOne
	@JoinColumn(name = "collaborateurId")
	private Employee employee;

	/**
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}

	/**
	 * @param date
	 *            the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}

	/**
	 * @return the charge
	 */
	public Float getCharge() {
		return charge;
	}

	/**
	 * @param charge
	 *            the charge to set
	 */
	public void setCharge(Float charge) {
		this.charge = charge;
	}

	/**
	 * @return the etc
	 */
	public Float getEtc() {
		return etc;
	}

	/**
	 * @param etc
	 *            the etc to set
	 */
	public void setEtc(Float etc) {
		this.etc = etc;
	}

	/**
	 * @return the comment
	 */
	public String getComment() {
		return comment;
	}

	/**
	 * @param comment
	 *            the comment to set
	 */
	public void setComment(String comment) {
		this.comment = comment;
	}

	/**
	 * @return the task
	 */
	public Task getTask() {
		return task;
	}

	/**
	 * @param task
	 *            the task to set
	 */
	public void setTask(Task task) {
		this.task = task;
	}

	/**
	 * @return the employee
	 */
	public Employee getEmployee() {
		return employee;
	}

	/**
	 * @param employee
	 *            the employee to set
	 */
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	@Override
	public int compareTo(Imputation t) {
		return this.date.compareTo(t.date);
	}

}
